home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 4
/
Aminet 4 - November 1994.iso
/
aminet
/
comm
/
term
/
term41source.lha
/
Extras
/
Source
/
term-Source.lha
/
SoundPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-30
|
10KB
|
411 lines
/*
** SoundPanel.c
**
** Editing panel for sound configuration
**
** Copyright © 1990-1994 by Olaf `Olsen' Barthel
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_BELL=1,GAD_CONNECT,GAD_DISCONNECT,GAD_GOOD_TRANSFER,
GAD_BAD_TRANSFER,GAD_RING,GAD_VOICE,GAD_PRELOAD,GAD_VOLUME,
GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL
};
BYTE __regargs
SoundPanel(struct SoundConfig *Config)
{
struct LayoutHandle *Handle;
STATIC struct SoundConfig __far BackupConfig;
CopyMem(Config,&BackupConfig,sizeof(struct SoundConfig));
if(Handle = LT_CreateHandleTags(Window -> WScreen,
LH_LocaleHook, &LocaleHook,
TAG_DONE))
{
struct Window *PanelWindow;
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
LA_LabelID, MSG_V36_0182,
TAG_DONE);
{
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_BELL_GAD,
LA_STRPTR, Config -> BellFile,
LA_Chars, 30,
LA_ID, GAD_BELL,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_CONNECT_GAD,
LA_STRPTR, Config -> ConnectFile,
LA_ID, GAD_CONNECT,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_DISCONNECT_GAD,
LA_STRPTR, Config -> DisconnectFile,
LA_ID, GAD_DISCONNECT,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_GOOD_TRANSFER_GAD,
LA_STRPTR, Config -> GoodTransferFile,
LA_ID, GAD_GOOD_TRANSFER,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_BAD_TRANSFER_GAD,
LA_STRPTR, Config -> BadTransferFile,
LA_ID, GAD_BAD_TRANSFER,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_RING_GAD,
LA_STRPTR, Config -> RingFile,
LA_ID, GAD_RING,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_New(Handle,
LA_Type, STRING_KIND,
LA_LabelID, MSG_SOUNDPANEL_VOICE_GAD,
LA_STRPTR, Config -> VoiceFile,
LA_ID, GAD_VOICE,
LAST_Picker, TRUE,
GTST_MaxChars, MAX_FILENAME_LENGTH - 1,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type, XBAR_KIND,
TAG_DONE);
LT_New(Handle,
LA_Type, VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, SLIDER_KIND,
LA_LabelID, MSG_SOUNDPANEL_VOLUME_GAD,
LA_BYTE, &Config -> Volume,
LA_ID, GAD_VOLUME,
LA_Chars, 10,
GTSL_Min, 0,
GTSL_Max, 100,
GTSL_LevelFormat, "%ld%%",
TAG_DONE);
LT_New(Handle,
LA_Type, CHECKBOX_KIND,
LA_LabelID, MSG_SOUNDPANEL_PRELOAD_GAD,
LA_BYTE, &Config -> Preload,
LA_ID, GAD_PRELOAD,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
LT_New(Handle,
LA_Type,VERTICAL_KIND,
TAG_DONE);
{
LT_New(Handle,
LA_Type, XBAR_KIND,
LAXB_FullSize, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_New(Handle,LA_Type,HORIZONTAL_KIND,
LAGR_SameSize, TRUE,
LAGR_Spread, TRUE,
TAG_DONE);
{
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_USE_GAD,
LA_ID, GAD_USE,
LABT_ReturnKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_LOAD_GAD,
LA_ID, GAD_LOAD,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_SAVE_GAD,
LA_ID, GAD_SAVE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_New(Handle,
LA_Type, BUTTON_KIND,
LA_LabelID, MSG_GLOBAL_CANCEL_GAD,
LA_ID, GAD_CANCEL,
LABT_EscKey, TRUE,
LABT_ExtraFat, TRUE,
TAG_DONE);
LT_EndGroup(Handle);
}
LT_EndGroup(Handle);
}
if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_SOUNDPANEL_SOUND_PREFERENCES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
LAWN_HelpHook, &GuideHook,
LAWN_Parent, Window,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_DragBar, TRUE,
WA_RMBTrap, TRUE,
WA_Activate, TRUE,
TAG_DONE))
{
struct IntuiMessage *Message;
BOOLEAN Done = FALSE;
ULONG MsgClass,
MsgQualifier;
UWORD MsgCode;
struct Gadget *MsgGadget;
STRPTR DummyChar;
UBYTE DummyBuffer[MAX_FILENAME_LENGTH];
struct FileRequester *FileRequest;
GuideContext(CONTEXT_SOUND);
PushWindow(PanelWindow);
do
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
{
CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
break;
}
while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
{
MsgClass = Message -> Class;
MsgQualifier = Message -> Qualifier;
MsgCode = Message -> Code;
MsgGadget = (struct Gadget *)Message -> IAddress;
GT_ReplyIMsg(Message);
LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
if(MsgClass == IDCMP_CLOSEWINDOW)
{
CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
Done = TRUE;
}
if(MsgClass == IDCMP_GADGETUP)
{
switch(MsgGadget -> GadgetID)
{
case GAD_USE:
SoundChanged = memcmp(&BackupConfig,Config,sizeof(struct SoundConfig));
Done = TRUE;
break;
case GAD_CANCEL:
CopyMem(&BackupConfig,Config,sizeof(struct SoundConfig));
Done = TRUE;
break;
case GAD_LOAD:
SplitFileName(LastSound,&DummyChar,DummyBuffer);
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_LOAD_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
{
if(!ReadIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
ShowError(PanelWindow,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
else
{
SoundChanged = FALSE;
strcpy(LastSound,DummyBuffer);
LT_SetAttributes(Handle,GAD_BELL,
GTST_String,Config -> BellFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_CONNECT,
GTST_String,Config -> ConnectFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_DISCONNECT,
GTST_String,Config -> DisconnectFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_GOOD_TRANSFER,
GTST_String,Config -> GoodTransferFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_BAD_TRANSFER,
GTST_String,Config -> BadTransferFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_RING,
GTST_String,Config -> RingFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_VOICE,
GTST_String,Config -> VoiceFile,
TAG_DONE);
LT_SetAttributes(Handle,GAD_PRELOAD,
GTCB_Checked,Config -> Preload,
TAG_DONE);
LT_SetAttributes(Handle,GAD_VOLUME,
GTSL_Level,Config -> Volume,
TAG_DONE);
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
break;
case GAD_SAVE:
SplitFileName(LastSound,&DummyChar,DummyBuffer);
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_SAVE_SOUNDS_TXT),DummyBuffer,FilePart(LastSound),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
{
if(!WriteIFFData(DummyBuffer,Config,sizeof(struct SoundConfig),ID_SOUN))
ShowError(PanelWindow,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
else
{
strcpy(LastSound,DummyBuffer);
SoundChanged = FALSE;
}
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
break;
default:
if(MsgGadget -> GadgetID >= GAD_BELL && MsgGadget -> GadgetID <= GAD_VOICE)
{
if(MsgCode == '\r' && Config -> Volume)
{
STRPTR Name;
LT_LockWindow(PanelWindow);
Name = (STRPTR)LT_GetAttributes(Handle,MsgGadget -> GadgetID,TAG_DONE);
if(Name[0])
{
struct SoundInfo *SoundInfo;
if(SoundInfo = LoadSound(Name,FALSE))
{
PlaySound(SoundInfo);
FreeSound(SoundInfo);
}
}
LT_UnlockWindow(PanelWindow);
}
}
break;
}
}
if(MsgClass == IDCMP_IDCMPUPDATE && MsgGadget -> GadgetID >= GAD_BELL && MsgGadget -> GadgetID <= GAD_VOICE)
{
SplitFileName((STRPTR)LT_GetAttributes(Handle,MsgGadget -> GadgetID,TAG_DONE),&DummyChar,DummyBuffer);
LT_LockWindow(PanelWindow);
if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_SOUNDPANEL_SELECT_BELL_TXT + MsgGadget -> GadgetID - GAD_BELL),DummyBuffer,DummyChar,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
{
LT_SetAttributes(Handle,MsgGadget -> GadgetID,
GTST_String,DummyBuffer,
TAG_DONE);
FreeAslRequest(FileRequest);
}
LT_UnlockWindow(PanelWindow);
}
}
}
while(!Done);
PopWindow();
}
LT_DeleteHandle(Handle);
}
return((BYTE)memcmp(&BackupConfig,Config,sizeof(struct SoundConfig)));
}